package com.newland.starpos.partner.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@EnableAsync
@Configuration
public class AsyncConfiguration {

    /**
     * 	<li>异步线程池</li>
     */
    @Bean(name = "asyncExecutor")
    public AsyncTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setThreadNamePrefix("asyncExecutor-");
        executor.setCorePoolSize(5);// 核心线程数
        executor.setMaxPoolSize(20);// 最大线程数
        executor.setKeepAliveSeconds(300);// 空闲线程最大存活时间
        executor.setQueueCapacity(50);// 缓冲队列大小
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(10);
        return executor;
    }
}
